﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using SlaughterItem.API.Application.Commands.Week02.AddWeighingSheet;
using SlaughterItem.API.Application.Commands.Week02.Setups;
using SlaughterItem.Common.Dtos;

namespace SlaughterItem.API.Controllers.SuYi
{
    /// <summary>
    /// 第二周任务 待宰圈 折扣项 副产品称重
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class Week2SetupController : ControllerBase
    {
        /// <summary>
        /// 中介者
        /// </summary>
         IMediator mediator;
        /// <summary>
        /// 日志
        /// </summary>
        ILogger<Week2SetupController> logger;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="mediator">中介者</param>
        /// <param name="logger">日志</param>
        public Week2SetupController(IMediator mediator, ILogger<Week2SetupController> logger)
        {
            this.mediator = mediator;
            this.logger = logger;
        }
        /// <summary>
        /// 待宰圈设置添加
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Result>AddWaiting(WaitingCreateCommand cmd)
        {
            try
            {
                logger.LogInformation("待宰圈设置添加");
                return await mediator.Send(cmd);
            }
            catch (Exception ex)
            {
                logger.LogError("待宰圈设置添加失败" + ex.Message);

                throw;
            }
        }
        /// <summary>
        /// 折扣设置添加
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Result> AddDeductions(DeductionsCreateCommand cmd)
        {
            try
            {
                logger.LogInformation("折扣设置添加");
                return await mediator.Send(cmd);
            }
            catch (Exception ex)
            {
                logger.LogError("折扣设置添加失败" + ex.Message);

                throw;
            }
        }

        /// <summary>
        /// 待宰圈设置删除
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Result> DeleteWaiting(WaitingDeleteCommand cmd)
        {
            try
            {
                logger.LogInformation("待宰圈设置删除");
                return await mediator.Send(cmd);
            }
            catch (Exception ex)
            {
                logger.LogError("待宰圈设置删除失败" + ex.Message);

                throw;
            }
        }
        /// <summary>
        /// 折扣设置删除
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Result> DeleteDeductions(DeductionsDeleteCommand cmd)
        {
            try
            {
                logger.LogInformation("折扣设置删除");
                return await mediator.Send(cmd);
            }
            catch (Exception ex)
            {
                logger.LogError("折扣设置删除失败" + ex.Message);

                throw;
            }
        }

        /// <summary>
        /// 副产称重添加
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Result> AddWeighingSheet(AddWeighingSheetCommand cmd)
        {
            try
            {
                logger.LogInformation("副产称重添加");
                return await mediator.Send(cmd);
            }
            catch (Exception ex)
            {
                logger.LogError("副产称重添加失败" + ex.Message);

                throw;
            }
        }
    }
}
